package net.lab1024.sa.admin.module.yitihua.service;

import java.util.List;
import net.lab1024.sa.admin.module.yitihua.dao.Cfs119CommunityDao;
import net.lab1024.sa.admin.module.yitihua.domain.entity.Cfs119Community;
import net.lab1024.sa.admin.module.yitihua.domain.form.Cfs119CommunityAddForm;
import net.lab1024.sa.admin.module.yitihua.domain.form.Cfs119CommunityQueryForm;
import net.lab1024.sa.admin.module.yitihua.domain.form.Cfs119CommunityUpdateForm;
import net.lab1024.sa.admin.module.yitihua.domain.vo.Cfs119CommunityVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 一体化平台社区信息 Service
 *
 * @Author cfsjiazy
 * @Date 2025-09-12 10:03:37
 * @Copyright  
 */

@Service
public class Cfs119CommunityService {

    @Resource
    private Cfs119CommunityDao cfs119CommunityDao;

    /**
     * 分页查询
     */
    public PageResult<Cfs119CommunityVO> queryPage(Cfs119CommunityQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<Cfs119CommunityVO> list = cfs119CommunityDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(Cfs119CommunityAddForm addForm) {
        Cfs119Community cfs119CommunityEntity = SmartBeanUtil.copy(addForm, Cfs119Community.class);
        cfs119CommunityDao.insert(cfs119CommunityEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(Cfs119CommunityUpdateForm updateForm) {
        Cfs119Community cfs119CommunityEntity = SmartBeanUtil.copy(updateForm, Cfs119Community.class);
        cfs119CommunityDao.updateById(cfs119CommunityEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<String> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        cfs119CommunityDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(String id) {
        if (null == id){
            return ResponseDTO.ok();
        }

        cfs119CommunityDao.deleteById(id);
        return ResponseDTO.ok();
    }

    public void addBatch(List<Cfs119Community> list) {
        cfs119CommunityDao.insertBatch(list);
    }
}
